package com.xjoyt.pay.share.services;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xjoyt.pay.abstracts.AbstractService;
import com.xjoyt.pay.dto.ExecuteResult;
import com.xjoyt.pay.dto.PageParam;
import com.xjoyt.pay.dto.PageResult;
import com.xjoyt.pay.share.params.BankPageParam;
import com.xjoyt.pay.share.po.Bank;
import com.xjoyt.pay.share.repository.BankRepository;

@Service
public class BankService extends AbstractService {

	@Autowired
	private BankRepository repository;

	public Bank get(String id) {
		return repository.findOne(id);
	}

	public ExecuteResult<Bank> save(Bank entity) {
		if (entity.addedDate == null)
			entity.addedDate = new Date();
		entity = repository.save(entity);
		return ExecuteResult.ok(entity);
	}

	public PageResult<Bank> loadPage(PageParam<BankPageParam> param) {
		return repository.loadPage(param);
	}

	public ExecuteResult<?> remove(String id) {
		repository.delete(id);
		return ExecuteResult.ok();
	}
}
